﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeBehind="ServiceReportJobCreator.aspx.cs" Inherits="SEP.Admin.ServiceReportJobCreator" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" runat="server">
    <script src="../Scripts/jquery-ui.min.js" type="text/javascript"></script>
    <link href="../Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDefaultBehavior();

            if (isPostBack() == "False") {
                RegisterHideModalBehavior();
                RegisterModalBehavior();
            } else {

            }

            //when update panel contents are refreshed, document.ready() is *not* called again
            //so we register an endrequest handler which will re-register our behavior
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(UpdatePanelRequestHandler);
        });

        function isPostBack() {
          return "<%= Page.IsPostBack %>";
        }

        function UpdatePanelRequestHandler() {
            RegisterDefaultBehavior();

            $("#searchLocation").hide();
            $("#searchBillTo").hide();
        }

        function RegisterDefaultBehavior() {
            RegisterSameAsLocationBehavior();
            DefineInputMasks();
        }

        function RegisterHideModalBehavior() {            
            if (!$("#modalLocation").is(":hidden")) {
                $("#modalLocation").hide();
            }
        }

        function RegisterModalBehavior() {
            $("#searchLocation").click(function () {
                ToggleModal("#modalLocation");                
            });

            $("#searchBillTo").click(function () {
                ToggleModal("#modalLocation");
            });
        }

        function ToggleModal(divName){
            var options = {};

            $(divName).toggle("blind", options, 500);

            $("#searchLocation").hide();
            $("#searchBillTo").hide();
        }

        function RegisterSameAsLocationBehavior() {
            $("#<%= chkCopyLocation.ClientID %>").click(function () {
                if ($("#<%= chkCopyLocation.ClientID  %>").is(":checked")) {
                    $("#<%= txtBillToFacility.ClientID %>").val($("#<%= txtLocationFacility.ClientID %>").val());
                    $("#<%= txtBillToStreet.ClientID %>").val($("#<%= txtLocationStreet.ClientID %>").val());
                    $("#<%= txtBillToCity.ClientID %>").val($("#<%= txtLocationCity.ClientID %>").val());
                    $("#<%= txtBillToContact.ClientID %>").val($("#<%= txtLocationContact.ClientID %>").val());
                    $("#<%= txtBillToPhone.ClientID %>").val($("#<%= txtLocationPhone.ClientID %>").val());
                    $("#<%= txtBillToExtension.ClientID %>").val($("#<%= txtLocationExtension.ClientID %>").val());
                    $("#<%= txtBillToEmail.ClientID %>").val($("#<%= txtLocationEmail.ClientID %>").val());
                    $("#<%= txtBillToFax.ClientID %>").val($("#<%= txtLocationFax.ClientID %>").val());
                    $("#<%= txtBillToZip.ClientID %>").val($("#<%= txtLocationZip.ClientID %>").val());
                    $("#<%= ddlBillToState.ClientID %>").val($("#<%= ddlLocationState.ClientID %>").val());
                }
            });
        }

        function DefineInputMasks() {
            $(".phone").mask("(999) 999-9999");
            $(".datepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphTitle" runat="server">
    Create A Job
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphBody" runat="server">
    <asp:Label ID="lblError" runat="server" ForeColor="Red" Font-Bold="true" Visible="false" />
    <table align="center">
        <tr>
            <td colspan="3">
                <table>
                    <tr>
                        <td>
                            <h3>
                                Job name</h3>
                        </td>
                        <td>
                            <asp:TextBox ID="txtJobName" runat="server" MaxLength="100" /><asp:RequiredFieldValidator
                                ID="rfvTxtJobName" runat="server" Text="* Required" ErrorMessage="Job name is required." ControlToValidate="txtJobName" ForeColor="Red" SetFocusOnError="true" />
                        </td>
                        <td>
                            <asp:TextBox ID="txtDate" runat="server" Width="70px" CssClass="datepicker" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <hr />
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:ScriptManager ID="ScriptManager1" runat="server" />
                <asp:UpdatePanel ID="updGrvLocationSearch" runat="server">
                    <ContentTemplate>
                        <div id="modalLocation">
                            <div class="modal">
                                <table width="800" border="0">
                                    <tr>
                                        <td colspan="2" align="right">
                                            <asp:TextBox ID="txtLocationSearch" runat="server" />
                                            <asp:Button ID="btnLocationSubmit" runat="server" Text="Search" CausesValidation="false"
                                                OnClick="btnLocationSubmit_Click" />
                                                <asp:Button ID="btnLocationReset" runat="server" Text="Reset" 
                                                CausesValidation="false" onclick="btnLocationReset_Click" />                                                
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" colspan="2">
                                            <asp:GridView ID="grvLocationSearch" runat="server" AutoGenerateColumns="false" PagerSettings-NextPageText="Next"
                                                PagerSettings-PreviousPageText="Previous" PagerSettings-Mode="NextPrevious" PageSize="5"
                                                AllowPaging="true" OnPageIndexChanging="grvLocationSearch_PageIndexChanging"
                                                AllowSorting="true" OnSorting="grvLocationSearch_OnSorting" Width="750" 
                                                EmptyDataText="There aren't any customers that match that criteria." 
                                                OnRowCommand="grvLocationSearch_OnRowCommand">
                                                <Columns>
                                                    <asp:ButtonField Text="Location" CommandName="LOCATION" ButtonType="Link" />
                                                    <asp:ButtonField Text="Bill To" CommandName="BILLTO" ButtonType="Link" />
                                                    <asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME" />
                                                    <asp:BoundField DataField="STREET" HeaderText="Street" SortExpression="STREET" Visible="false" />
                                                    <asp:BoundField DataField="CITY" HeaderText="City" SortExpression="CITY" Visible="false" />
                                                    <asp:BoundField DataField="POSTCODE" HeaderText="Post code" SortExpression="POSTCODE"
                                                        Visible="false" />
                                                    <asp:BoundField DataField="STATE" HeaderText="State" SortExpression="STATE" Visible="false" />
                                                    <asp:BoundField DataField="PHONE" HeaderText="Phone" SortExpression="PHONE" />
                                                    <asp:BoundField DataField="FAX" HeaderText="Fax" SortExpression="FAX" Visible="false" />
                                                    <asp:BoundField DataField="EMAILADDRESS" HeaderText="Email" SortExpression="EMAILADDRESS" />
                                                    <asp:TemplateField HeaderText="Contact" SortExpression="CONTACT">
                                                        <ItemTemplate>
                                                            <%# Eval("CONTACT") %>
                                                            <asp:HiddenField ID="hidID" runat="server" Value='<%# Eval("ID") %>' />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:GridView>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <table>
                            <tr>
                                <td class="alignLeft">
                                    <h3>
                                        Location</h3>
                                </td>
                                <td class="alignRight">
                                    <a id="searchLocation" style="cursor:pointer;">Search</a>
                                </td>
                            </tr>
                            <tr>
                                <td class="alignLeft" colspan="2">
                                    <table rules="all" border="1" cellpadding="10" cellspacing="10">
                                        <tr>
                                            <td>
                                                Facility
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationFacility" runat="server" Columns="42" TabIndex="1" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top">
                                                Street
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationStreet" runat="server" MaxLength="1000" Columns="32"
                                                    row="3" TabIndex="2" TextMode="MultiLine" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                City, State, Zip
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationCity" runat="server" MaxLength="50" TabIndex="3" /><asp:DropDownList
                                                    ID="ddlLocationState" runat="server" TabIndex="4" />
                                                <asp:TextBox ID="txtLocationZip" runat="server" MaxLength="10" Columns="7" TabIndex="5" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Contact
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationContact" runat="server" MaxLength="200" Columns="42"
                                                    TabIndex="6" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Phone
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationPhone" runat="server" CssClass="phone" TabIndex="7" />
                                                ext.<asp:TextBox ID="txtLocationExtension" runat="server" MaxLength="10" Columns="10"
                                                    TabIndex="8" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Fax
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationFax" runat="server" CssClass="phone" TabIndex="9" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Email
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtLocationEmail" runat="server" Columns="42" TabIndex="10" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <hr />
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:UpdatePanel ID="updGrvBillToSearch" runat="server">
                    <ContentTemplate>                     
                        <table>
                            <tr>
                                <td class="alignLeft">
                                    <h3>
                                        Bill to</h3>
                                    <asp:CheckBox ID="chkCopyLocation" runat="server" Text="Same as location" />
                                </td>
                                <td class="alignRight">
                                    <a id="searchBillTo" style="cursor:pointer;">Search</a>
                                </td>
                            </tr>
                            <tr>
                                <td class="alignLeft" colspan="2">
                                    <table rules="all" border="1" cellpadding="10" cellspacing="10">
                                        <tr>
                                            <td>
                                                Facility
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToFacility" runat="server" Columns="42" TabIndex="11" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top">
                                                Street
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToStreet" runat="server" MaxLength="1000" TabIndex="12" Columns="32"
                                                    row="3" TextMode="MultiLine" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                City, State, Zip
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToCity" runat="server" MaxLength="50" TabIndex="13" /><asp:DropDownList
                                                    ID="ddlBillToState" runat="server" TabIndex="14" />
                                                <asp:TextBox ID="txtBillToZip" runat="server" MaxLength="10" Columns="7" TabIndex="15" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Contact
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToContact" runat="server" MaxLength="200" Columns="42" TabIndex="16" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Phone
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToPhone" runat="server" CssClass="phone" TabIndex="17" />
                                                ext.<asp:TextBox ID="txtBillToExtension" runat="server" MaxLength="10" Columns="10"
                                                    TabIndex="18" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Fax
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToFax" runat="server" CssClass="phone" TabIndex="19" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Email
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtBillToEmail" runat="server" Columns="42" TabIndex="20" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:Button ID="btnSubmit" runat="server" Text="Create" OnClick="btnSubmit_OnClick" />
            </td>
        </tr>
    </table>
    <asp:ValidationSummary ID="validationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" />
</asp:Content>
